'''
/*
 * @Author: wevsmy 
 * @Date: 2017-10-23 17:00:49 
 * @Last Modified by: wevsmy
 * @Last Modified time: 2017-10-23 19:23:20
 */
'''
import os
import time
ret = os.fork()

print(ret)

g_num = 100
#多次fork 
if ret == 0:
    print("----1-----")
    g_num += 1
    print("1共同执行%d"%g_num)
    ret1 = os.fork()
    if ret1 == 0:
        print("----21-----")
        g_num += 1
        print("21共同执行%d"%g_num)
    else:
        print("----22-----")
        
        time.sleep(3)
        print("22共同执行%d"%g_num)
else:
    print("----2-----")
    
    time.sleep(3)
    print("2共同执行%d"%g_num)
    

print("共同执行%d"%g_num)

#父进程子进程执行的顺序不确定，要看操作系统的调度算法